import 'package:beautiful_demo/common/empty.dart';
import 'package:beautiful_demo/common/res.dart';
import 'package:beautiful_demo/common/widget/widget.dart';
import 'package:drive/drive.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_mvc/flutter_mvc.dart';

import 'controller.dart';

///description:聊天列表

class ScreenWidget extends MvcStatelessWidget<ChatListController> {
  final items = ["消息", "通讯录"];

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60.dp,
      padding: EdgeInsets.only(left: 20.dp, right: 20.dp),
      child: Row(
        children: [
          for (var i = 0; i < items.length; i++) _buildItem(items[i], i)
        ],
      ),
    );
  }

  Widget _buildItem(String title, int index) {
    final isSelect = index == c.index;
    final fontSize = isSelect ? 20.sp : 16.sp;
    final fontWidget = isSelect ? FontWeight.w600 : FontWeight.w400;

    return GestureDetector(
      onTap: ()=>c.onScreenItemClick(index),
      child: Container(
        padding: EdgeInsets.only(right: 40.dp),
        child: Stack(
          children: [
            if (isSelect)
              Positioned.fill(
                child: LayoutBuilder(builder: (context, c) {
                  return Container(
                    height: 16.dp,
                    margin: EdgeInsets.only(
                      top: 15.dp,
                    ),
                    width: c.maxWidth,
                    decoration: BoxDecoration(
                        boxShadow: const [
                          BoxShadow(
                              color: Color(0x88bbd7fb),
                              offset: Offset(3, 5),
                              blurRadius: 5)
                        ],
                        color: const Color(0xffbbd7fb),
                        borderRadius: BorderRadius.circular(10.dp)),
                  );
                }),
              ),
            Container(
                padding: EdgeInsets.only(right: 6.dp, bottom: 4.dp),
                child: Text(
                  title,
                  style: resTextStyle30.copyWith(
                      fontSize: fontSize, fontWeight: fontWidget),
                )),
          ],
        ),
      ),
    );
  }
}

class Item extends StatelessWidget {
  final String url;
  final String title;
  final String message;
  final String tips;
  final String time;

  const Item(this.url, this.title, this.message,this.time, this.tips, {Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 84.dp,
      child: Column(
        children: [
          Expanded(
              child: Row(
                children: [
                  SizedBox(
                    width: 20.dp,
                  ),
                  CachedImageShadow(
                    url: url,
                    width: 60.dp,
                    height: 60.dp,
                    boxShadow: const [
                      BoxShadow(
                          color: Color(0x11333333),
                          offset: Offset(-2, 0),
                          blurRadius: 3)
                    ],),
                  // ClipRRect(
                  //     borderRadius: BorderRadius.circular(60.dp),
                  //     child: CachedImage(
                  //       url,
                  //
                  //       fit: BoxFit.cover,
                  //     )),
                  SizedBox(
                    width: 10.dp,
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          title,
                          style: resTextStyle.copyWith(
                              color: const Color(0xff000000),
                              fontSize: 18.sp,
                          shadows: const [
                            BoxShadow(
                                color: Color(0x27333333),
                                offset: Offset(0, 1),
                                blurRadius: 3)
                          ],
                          fontWeight: FontWeight.w500),
                        ),
                        SizedBox(
                          height: 10.dp,
                        ),
                        Text(
                          message,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: resTextStyle.copyWith(
                          //     shadows: const[
                          //   BoxShadow(
                          //       color: Color(0x27999999),
                          //       offset: Offset(-1, 1),
                          //       blurRadius: 3)
                          // ],
                              color: const Color(0xffaaaaaa), fontSize: 13.sp),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    width: 15.dp,
                  ),
                  if (tips != "" && int.parse(tips) != 0)
                    Container(
                      alignment: Alignment.topLeft,
                      child: Container(
                        padding: EdgeInsets.only(left: 5.dp, right: 5.dp),
                        margin: EdgeInsets.only(top: 13.dp),
                        height: 21.dp,
                        constraints: BoxConstraints(minWidth: 21.dp),
                        decoration: BoxDecoration(
                            color: const Color(0xeeff2b2b),
                            boxShadow: const [
                              BoxShadow(
                                  color: Color(0x22ff2b2b),
                                  offset: Offset(2, -1),
                                  blurRadius: 3)
                            ],
                            borderRadius: BorderRadius.circular(18.dp)),
                        alignment: Alignment.center,
                        child: Text(
                          tips,
                          style: resTextStyle.copyWith(
                            fontSize: 12.sp,
                          ),
                        ),
                      ),
                    )
                  else
                    Container(
                      width: 21.dp,
                    ),
                  SizedBox(
                    width: 23.dp,
                  ),
                ],
              )),
          LineWidget(
            color: Color(0xf1f1f3f6),
          )
        ],
      ),
    );
  }
}
